package com.hospital.workstation.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.hospital.workstation.domain.vo.HisMedicineInfoImportVo;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.hospital.common.annotation.RepeatSubmit;
import com.hospital.common.annotation.Log;
import com.hospital.common.core.controller.BaseController;
import com.hospital.common.core.domain.PageQuery;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.validate.AddGroup;
import com.hospital.common.core.validate.EditGroup;
import com.hospital.common.core.validate.QueryGroup;
import com.hospital.common.enums.BusinessType;
import com.hospital.common.utils.poi.ExcelUtil;
import com.hospital.workstation.domain.vo.HisMedicineInfoVo;
import com.hospital.workstation.domain.bo.HisMedicineInfoBo;
import com.hospital.workstation.service.IHisMedicineInfoService;
import com.hospital.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 药品信息
 *
 * @author whb
 * @date 2023-05-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workstation/medicineInfo")
public class HisMedicineInfoController extends BaseController {

    private final IHisMedicineInfoService iHisMedicineInfoService;

    /**
     * 查询药品信息列表
     */
    // @SaCheckPermission("workstation:medicineInfo:list")
    @GetMapping("/list")
    public TableDataInfo<HisMedicineInfoVo> list(HisMedicineInfoBo bo, PageQuery pageQuery) {
        return iHisMedicineInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取导入模板
     *
     * @param response
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "药品信息", HisMedicineInfoImportVo.class, response);
    }

    /**
     * 导入药品信息
     *
     * @param file 药品信息文件
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<Void> importData(@RequestPart("file") MultipartFile file) throws Exception {
        List<HisMedicineInfoImportVo> medicineInfoImportVoList = ExcelUtil.importExcel(file.getInputStream(), HisMedicineInfoImportVo.class);
        return iHisMedicineInfoService.addBatchMedicalInfo(medicineInfoImportVoList);
    }
}
